<?php


namespace app\lunwen\controller;


use app\admin\model\ThemeFileModel;
use app\lunwen\model\DepartmentUploadFileModel;
use app\lunwen\model\TeacherUploadFileModel;
use cmf\controller\HomeBaseController;
use think\response\Download;

class DepartmentFileOperateController extends HomeBaseController
{
    public function index(){

    }

    public function downFile(){
        $file = new TeacherUploadFileModel();
        $data = $file->where('status','in','导师已提交,院系通过,院系不通过')
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':departmentDownFile');
    }

    public function uploadFile(){
        $file = new DepartmentUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentUpload');
    }

    public function delete(){
        //echo $_GET["stu_id"];
        //echo $_GET["file_name"];
        //删除文件
        echo $filename = "D:\phpstudy_pro\\thinkcmf\ThinkCMF\public\static\departmentFile\\{$_GET["file_name"]}";
        unlink($filename);

        //删除数据库
        $del = new DepartmentUploadFileModel();
        $del->where('stu_id',$_GET["stu_id"])
            ->where('file_name',$_GET["file_name"])
            ->delete();

        $file = new DepartmentUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('title',$data);
        return $this->fetch(':departmentUpload');
    }

    public function downButton(){

        $data = "D:\phpstudy_pro\\thinkcmf\ThinkCMF\public\static\\file\\{$_GET["file_name"]}";
        echo $filename = $_GET["file_name"];
        return \download($data,$_GET["file_name"],false);
        
    }

    public function passWord(){
        //改状态为院系通过 返回一个成功
        $teacherFile = new TeacherUploadFileModel();
        $teacherFile->where("file_name",$_GET["fileName"])
            ->update(['status' =>'院系通过']);
        echo "<script>alert('成功！')</script>";

        $file = new TeacherUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':departmentDownFile');
    }

    public function notPassWord(){
        //改状态为院系不通过
        //改状态为院系通过 返回一个成功
        $teacherFile = new TeacherUploadFileModel();
        $teacherFile->where("file_name",$_GET["fileName"])
            ->update(['status' =>'院系不通过']);
        echo "<script>alert('成功！')</script>";

        $file = new TeacherUploadFileModel();
        $data = $file
            ->whereTime('create_time','>',session('beforeYear'))
            ->whereTime('create_time','<',session('afterYear'))
            ->all();
        $this->assign('file',$data);
        return $this->fetch(':departmentDownFile');
    }

}